package hsl.study.config;


import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description:
 * @Author: hsl
 * @CreateDate: 2025/7/31 14:30
 * @Version: 1.0
 */

@Configuration
public class LLMConfig {
    @Value("${spring.ai.openai.api-key}")
    private String apiKey;

    @Value("${spring.ai.openai.base-url}")
    private String baseUrl;

    // 模型名称使用常量进行定义
    private final String DEEPSEEK_MODEL = "deepseek-v3";
    private final String QWEN_PLUS_MODEL = "qwen-plus";

    // 进行bean构造
    @Bean(name = "deepseek")
    public OpenAiChatModel deepSeek() {
        return OpenAiChatModel.builder()
                .openAiApi(
                        OpenAiApi.builder()
                                .apiKey(apiKey)
                                .baseUrl(baseUrl)
                                .build()
                )
                .defaultOptions(
                        OpenAiChatOptions.builder()
                                .model(DEEPSEEK_MODEL)
                                .build()
                )
                .build();
    }

    @Bean(name = "qwenPlus")
    public OpenAiChatModel qwenPlus() {
        return OpenAiChatModel.builder()
                .openAiApi(
                        OpenAiApi.builder()
                                .apiKey(apiKey)
                                .baseUrl(baseUrl)
                                .build()
                )
                .defaultOptions(
                        OpenAiChatOptions.builder()
                                .model(QWEN_PLUS_MODEL)
                                .build()
                )
                .build();
    }

    @Bean(name = "deepseekChatClient")
    public ChatClient dsClient(@Qualifier("deepseek") OpenAiChatModel openAiChatModel) {
        return ChatClient.builder(openAiChatModel)
                .defaultOptions(
                        ChatOptions.builder()
                                .model("deepseek-v3")
                                .build()
                )
                .build();
    }

    @Bean(name = "qwenPlusChatClient")
    public ChatClient qwenClient(@Qualifier("qwenPlus") OpenAiChatModel openAiChatModel) {
        return ChatClient.builder(openAiChatModel)
                .defaultOptions(
                        ChatOptions.builder()
                                .model("qwen-max")
                                .build()
                )
                .build();
    }
}

